﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BatchUserRole.aspx.cs" Inherits="SYS_POPEDOM_BatchUserRole" EnableViewState="true" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>批量分配用户角色</title>
    <style type="text/css">
        .no-icon
        {
            display: none;
        }
    </style>

    <script type="text/javascript" src="../JavaScript/Common.js"></script>

    <link href="../css/PageStyle.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">

        function nodeLoad(node) {
            Ext.net.DirectMethods.NodeLoad(node.id, {
                success: function(result) {
                    var data = eval("(" + result + ")");
                    node.loadNodes(data);
                },

                failure: function(errorMsg) {
                    Ext.Msg.alert('Failure', errorMsg);
                }
            });
        }

        function nodeClick(node) {
            Ext.net.DirectMethods.NodeClick(node.id);
        }

        function clickNode(node) {
            TreePanel1.fireEvent("click", node);
        }


        function SelectionChange(item) {
            if (CheckAll) {
                index--;
                if (index != 0) {
                    return;
                }
            }
            GridPanel2.clear()
            var sel = item.getSelections();
            Ext.each(sel, function(record) {
                GridPanel2.addRecord(record.data);
            });
            GridPanel2.store.commitChanges();

        }

        var index = 0;
        var CheckAll = false;
        function BeforeCheckAllClick(item, checked) {
            index = GridPanel1.store.data.length;
            CheckAll = true;
        }

        function AfterCheckAllClick(item, checked) {
            CheckAll = false;
        }

        function nodeLoadWin(node) {
            var records = GridPanel3.store.getRecordsValues();
            var ids = [];
            Ext.each(records, function(data) {
                ids.push(data.MASTER_ID);
            });
            Ext.net.DirectMethods.NodeLoadWin(node.id, ids, {
                success: function(result) {
                    var data = eval("(" + result + ")");
                    node.loadNodes(data);
                },
                failure: function(errorMsg) {
                    Ext.Msg.alert('Failure', errorMsg);
                }
            });
        }


        function refreshTree(tree) {
            var records = GridPanel3.store.getRecordsValues();
            var ids = [];
            Ext.each(records, function(data) {
                ids.push(data.MASTER_ID);
            });
            tree.root.ui.remove();
            tree.root.render();
            Ext.net.DirectMethods.RefreshMenu(ids, {
                success: function(result) {
                    var nodes = eval(result);
                    tree.initChildren(nodes);
                    tree.root.render();
                }
            });

        }

        function gridCommand(command, record, rowIndex, colIndex) {
            if (command == "Remove") {
                GridPanel3.deleteRecord(record);
                GridPanel3.store.commitChanges();
            }
        }
        
        function SaveWin() {

            var records = GridPanel3.store.getRecordsValues();
            var ids = [];
            Ext.each(records, function(data) {
                ids.push(data.MASTER_ID);
            });
            var nodes = TreePanel2.getCheckedNodes();
            Ext.each(nodes, function(node) {
                ids.push(node.nodeID);
            });

            Ext.net.DirectMethods.AddSelectedNodes(ids);
            popWindow.hide();
        }

        function saveData() {
            var uRecords = GridPanel2.store.getRecordsValues();
            var uids = [];
            Ext.each(uRecords, function(data) {
                uids.push(data.USER_ID);
            });

            var mRecords = GridPanel3.store.getRecordsValues();
            var mids = [];
            Ext.each(mRecords, function(data) {
                mids.push(data.MASTER_ID);
            });
            if (uids.length == 0) {
                Ext.Msg.alert("系统提示", "请添加要分配角色的操作员!");
                return;
            }
            if (mids.length == 0) {
                Ext.Msg.alert("系统提示", "请添加要分配的角色!");
                return;
            }
            Ext.net.DirectMethods.SaveData(uids, mids);
        }
        
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:ResourceManager ID="ResourceManager1" runat="server" />
    <ext:Store ID="Store1" runat="server" AutoLoad="false" OnRefreshData="OnStoreRefreshData">
        <Reader>
            <ext:JsonReader IDProperty="USER_ID">
                <Fields>
                    <ext:RecordField Name="USER_ID" />
                    <ext:RecordField Name="USER_NAME" />
                    <ext:RecordField Name="DEPT_NAME" />
                    <ext:RecordField Name="OFFICE_PHONE" />
                    <ext:RecordField Name="INNER_PHONE" />
                    <ext:RecordField Name="CONTACT_PHONE" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="Store2" runat="server" AutoLoad="false">
        <Reader>
            <ext:JsonReader IDProperty="USER_ID">
                <Fields>
                    <ext:RecordField Name="USER_ID" />
                    <ext:RecordField Name="USER_NAME" />
                    <ext:RecordField Name="DEPT_NAME" />
                    <ext:RecordField Name="OFFICE_PHONE" />
                    <ext:RecordField Name="INNER_PHONE" />
                    <ext:RecordField Name="CONTACT_PHONE" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Store ID="Store3" runat="server" AutoLoad="true">
        <Reader>
            <ext:JsonReader IDProperty="MASTER_ID">
                <Fields>
                    <ext:RecordField Name="MASTER_ID" />
                    <ext:RecordField Name="ROLE_NAME" />
                    <ext:RecordField Name="DEPT_NAME" />
                    <ext:RecordField Name="DEPT_ID" />
                    <ext:RecordField Name="CREATOR" />
                </Fields>
            </ext:JsonReader>
        </Reader>
    </ext:Store>
    <ext:Viewport runat="server">
        <Items>
            <ext:ColumnLayout ID="ColumnLayout1" runat="server" Split="false" Border="false"
                FitHeight="true">
                <Columns>
                    <ext:LayoutColumn>
                        <ext:Panel ID="Panel1" runat="server" Border="false" Width="340">
                            <Items>
                                <ext:FitLayout ID="FitLayout1" runat="server">
                                    <Items>
                                        <ext:TreePanel ID="TreePanel1" runat="server" Collapsible="false" AutoScroll="true"
                                            Cls="tool-form" Animate="true" Border="false">
                                            <Listeners>
                                                <BeforeLoad Fn="nodeLoad" />
                                                <Click Fn="nodeClick" />
                                                <ExpandNode Fn="clickNode" />
                                                <CollapseNode Fn="clickNode" />
                                            </Listeners>
                                            <TopBar>
                                                <ext:Toolbar ID="Toolbar2" runat="server" Height="26">
                                                    <Items>
                                                        <ext:ToolbarTextItem Text="所属部门" Height="40">
                                                        </ext:ToolbarTextItem>
                                                        <ext:ToolbarFill ID="ToolbarFill2" runat="server" />
                                                        <ext:Button ID="Button4" runat="server" Text="" Width="0px" Disabled="true">
                                                        </ext:Button>
                                                    </Items>
                                                </ext:Toolbar>
                                            </TopBar>
                                        </ext:TreePanel>
                                    </Items>
                                </ext:FitLayout>
                            </Items>
                        </ext:Panel>
                    </ext:LayoutColumn>
                    <ext:LayoutColumn ColumnWidth="1">
                        <ext:Panel runat="server" Border="false" BodyStyle="border-width:1 0 1 1px;">
                            <Content>
                                <ext:RowLayout ID="RowLayout1" runat="server">
                                    <Rows>
                                        <ext:LayoutRow RowHeight="0.5">
                                            <ext:Panel ID="Panel2" runat="server" BodyStyle="border-width:0 0 0 1px;" Layout="Fit"
                                                Cls="tool-form">
                                                <Items>
                                                    <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" Border="false" AutoWidth="true"
                                                        Layout="Fit">
                                                        <ColumnModel ID="ColumnModel1" runat="server">
                                                            <Columns>
                                                                <ext:RowNumbererColumn Header="序号" Width="35" />
                                                                <ext:Column ColumnID="USER_ID" Css="" Header="<center>登陆帐号</center>" Sortable="true"
                                                                    DataIndex="USER_ID" Width="100">
                                                                </ext:Column>
                                                                <ext:Column Header="<center>操作员</center>" Width="100" Sortable="true" DataIndex="USER_NAME">
                                                                </ext:Column>
                                                                <ext:Column Header="<center>所在部门</center>" Width="100" Sortable="true" DataIndex="DEPT_NAME">
                                                                </ext:Column>
                                                            </Columns>
                                                        </ColumnModel>
                                                        <SelectionModel>
                                                            <ext:CheckboxSelectionModel ID="RowSelectionModel1" runat="server">
                                                                <Listeners>
                                                                    <SelectionChange Fn="SelectionChange" />
                                                                    <BeforeCheckAllClick Fn="BeforeCheckAllClick" />
                                                                    <AfterCheckAllClick Fn="AfterCheckAllClick" />
                                                                </Listeners>
                                                            </ext:CheckboxSelectionModel>
                                                        </SelectionModel>
                                                        <LoadMask />
                                                        <TopBar>
                                                            <ext:Toolbar ID="Toolbar1" runat="server">
                                                                <Items>
                                                                    <ext:TextField runat="server" ID="exttxtf_user_name" EmptyText="依姓名或拼音码查询...">
                                                                    </ext:TextField>
                                                                    <ext:Button ID="extBtn_Find" runat="server" Text="查询">
                                                                        <DirectEvents>
                                                                            <Click OnEvent="extBtn_Find_Click">
                                                                            </Click>
                                                                        </DirectEvents>
                                                                    </ext:Button>
                                                                </Items>
                                                            </ext:Toolbar>
                                                        </TopBar>
                                                    </ext:GridPanel>
                                                </Items>
                                            </ext:Panel>
                                        </ext:LayoutRow>
                                        <ext:LayoutRow RowHeight="0.5">
                                            <ext:Panel ID="Panel5" runat="server"  Cls="tool-form">
                                                <TopBar>
                                                    <ext:Toolbar ID="Toolbar4" runat="server">
                                                        <Items>
                                                            <ext:Label ID="Label1" runat="server" Text="操作员与科室角色">
                                                            </ext:Label>
                                                            <ext:ToolbarSeparator  runat="server" />
                                                            <ext:Button runat="server" Text=" 保存关系" Icon="Disk">
                                                                <Listeners>
                                                                    <Click Handler="saveData();" />
                                                                </Listeners>
                                                            </ext:Button>
                                                        </Items>
                                                    </ext:Toolbar>
                                                </TopBar>
                                                <Content>
                                                    <ext:ColumnLayout runat="server" >
                                                        <Columns>
                                                            <ext:LayoutColumn ColumnWidth="0.5" >
                                                                <ext:Panel ID="Panel3" runat="server" BodyStyle="border-width:0px 0px 0px 0px;" Layout="FitLayout"
                                                                    Cls="tool-form">
                                                                    <Items>
                                                                        <ext:GridPanel ID="GridPanel2" runat="server" StoreID="Store2" Border="false" AutoWidth="true"
                                                                            Layout="Fit" Title="待分配权限操作员">
                                                                            <ColumnModel ID="ColumnModel2" runat="server">
                                                                                <Columns>
                                                                                    <ext:RowNumbererColumn Header="序号" Width="35" />
                                                                                    <ext:Column ColumnID="USER_ID" Css="" Header="<center>登陆帐号</center>" Sortable="true"
                                                                                        DataIndex="USER_ID" Width="100">
                                                                                    </ext:Column>
                                                                                    <ext:Column Header="<center>操作员</center>" Width="100" Sortable="true" DataIndex="USER_NAME">
                                                                                    </ext:Column>
                                                                                    <ext:Column Header="<center>所在部门</center>" Width="100" Sortable="true" DataIndex="DEPT_NAME">
                                                                                    </ext:Column>
                                                                                </Columns>
                                                                            </ColumnModel>
                                                                            <SelectionModel>
                                                                                <ext:RowSelectionModel ID="RowSelectionModel2" runat="server">
                                                                                </ext:RowSelectionModel>
                                                                            </SelectionModel>
                                                                        </ext:GridPanel>
                                                                    </Items>
                                                                </ext:Panel>
                                                            </ext:LayoutColumn>
                                                            <ext:LayoutColumn ColumnWidth="0.5">
                                                                <ext:Panel runat="server" ID="ddd" BodyStyle="border-width:0px 0px 0px 1px;" Layout="FitLayout">
                                                                    <Content>
                                                                        <ext:Panel ID="Panel4" runat="server" Title="" Cls="tool-form" Border="false" Layout="FitLayout">
                                                                            <TopBar>
                                                                                <ext:Toolbar ID="Toolbar3" runat="server">
                                                                                    <Items>
                                                                                        <ext:Label ID="t" runat="server" Text="待分配角色">
                                                                                        </ext:Label>
                                                                                        <ext:ToolbarFill ID="ToolbarFill1" runat="server" />
                                                                                        <ext:Button ID="extBtn_Add" runat="server" Text=" 增加" Icon="Add">
                                                                                            <Listeners>
                                                                                                <Click Handler="refreshTree(#{TreePanel2});#{popWindow}.show();" />
                                                                                            </Listeners>
                                                                                        </ext:Button>
                                                                                    </Items>
                                                                                </ext:Toolbar>
                                                                            </TopBar>
                                                                            <Content>
                                                                                <ext:GridPanel ID="GridPanel3" runat="server" StoreID="Store3" Border="false">
                                                                                    <ColumnModel ID="ColumnModel3" runat="server">
                                                                                        <Columns>
                                                                                            <ext:RowNumbererColumn Header="序号" Width="35" />
                                                                                            <ext:Column Header="<center>角色名称</center>" Sortable="true" DataIndex="ROLE_NAME"
                                                                                                Width="200" />
                                                                                            <ext:Column Header="<center>部门名称</center>" Sortable="true" DataIndex="DEPT_NAME"
                                                                                                Width="200" />
                                                                                                
                                                                                            <ext:CommandColumn Width="50">
                                                                                                <Commands>
                                                                                                    <ext:GridCommand Icon="Delete" CommandName="Remove">
                                                                                                        <ToolTip Text="移除" />
                                                                                                    </ext:GridCommand>
                                                                                                </Commands>
                                                                                            </ext:CommandColumn>
                                                                                        </Columns>
                                                                                    </ColumnModel>
                                                                                    <Listeners>
                                                                                        <Command Fn="gridCommand" />
                                                                                    </Listeners>
                                                                                    <SelectionModel>
                                                                                        <ext:RowSelectionModel ID="CheckboxSelectionModel1" runat="server"  SingleSelect="true" >
                                                                                        </ext:RowSelectionModel>
                                                                                    </SelectionModel>
                                                                                    <LoadMask />
                                                                                </ext:GridPanel>
                                                                            </Content>
                                                                        </ext:Panel>
                                                                    </Content>
                                                                </ext:Panel>
                                                            </ext:LayoutColumn>
                                                        </Columns>
                                                    </ext:ColumnLayout>
                                                </Content>
                                            </ext:Panel>
                                        </ext:LayoutRow>
                                    </Rows>
                                </ext:RowLayout>
                            </Content>
                        </ext:Panel>
                    </ext:LayoutColumn>
                </Columns>
            </ext:ColumnLayout>
        </Items>
    </ext:Viewport>
    <ext:Window ID="popWindow" runat="server" Icon="Group" Title="选择角色" Width="400" Height="380"
        AutoShow="false" Modal="true" ShowOnLoad="false" Closable="true" Resizable="true"
        Hidden="true" Draggable="false">
        <Content>
            <ext:Panel runat="server" Border="false" Height="320" Layout="FitLayout">
                <Content>
                    <ext:TreePanel ID="TreePanel2" runat="server" Lines="true" Border="false" CollapseFirst="false"
                        AutoScroll="true" ContainerScroll="true">
                        <Listeners>
                            <BeforeLoad Fn="nodeLoadWin" />
                        </Listeners>
                        <LoadMask ShowMask="true" />
                    </ext:TreePanel>
                </Content>
            </ext:Panel>
        </Content>
        <TopBar>
            <ext:Toolbar runat="server">
                <Items>
                    <ext:Button ID="btnSave" runat="server" Text="确定" Icon="Disk">
                        <Listeners>
                            <Click Fn="SaveWin" />
                        </Listeners>
                    </ext:Button>
                    <ext:Button ID="btnCancel" runat="server" Text="关闭" Icon="Cancel">
                        <Listeners>
                            <Click Handler="popWindow.hide();" />
                        </Listeners>
                    </ext:Button>
                    <ext:ToolbarFill runat="server" />
                </Items>
            </ext:Toolbar>
        </TopBar>
    </ext:Window>
    </form>
</body>
</html>
